package com.ceshiren.springstudy.util;


import lombok.Data;

import java.io.Serializable;
import java.util.HashMap;

@Data
public class Result<T> implements Serializable {

    public static final long serialVersionUID = 1L;

    private String success;
    private Integer Code;
    private String message;
    private T data;

    public static <T> Result<T> success() {
        Result<T> result = new Result<T>();
        result.setCode(ResultCode.SUCCESS);
        result.setSuccess("true");
        result.setMessage("成功");
        return result;
    }

    public static <T> Result<T> error() {
        Result<T> result = new Result<T>();
        result.setCode(ResultCode.ERROR);
        result.setSuccess("false");
        result.setMessage("失败");
        result.setData((T)new HashMap<>());
        return result;
    }

    public Result<T> success(String success){
        this.setSuccess(success);
        return this;
    }

    public Result<T> code(Integer code){
        this.setCode(code);
        return this;
    }

    public Result<T> message(String message){
        this.setMessage(message);
        return this;
    }


    public Result<T> data(T data){
        this.setData(data);
        return this;
    }



}
